package com.kingint.web.admin.base.controller;


import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.admin.base.service.BasRepairGoodsService;
import com.kingint.mbg.bas.entity.BasRepairGoods;


/**
 * @描述：维修物品相关表控制类
 * @作者: wxh
 * @日期: 2020-12-22
 */
@RestController
@RequestMapping("/basRepairGoods")
@Api(value = "BasRepairGoodsController", description = "维修物品相关表")
@CrossOrigin
public class BasRepairGoodsController {

    @Autowired
    public BasRepairGoodsService basRepairGoodsService;


    @ApiOperation(value = "添加维修物品相关表")
    @PostMapping("/create")
//    @PreAuthorize("hasAuthority('basRepairGoods:create')")
    public Object create(@Validated(Insert.class) @RequestBody BasRepairGoods basRepairGoods) {
        return basRepairGoodsService.insertRepairGoodsInfo(basRepairGoods);
    }

    @ApiOperation(value = "更新维修物品相关表")
    @PutMapping("/update")
//    @PreAuthorize("hasAuthority('basRepairGoods:update')")
    public Object update(@Validated(Update.class) @RequestBody BasRepairGoods basRepairGoods) {
        int i = basRepairGoodsService.updateRepairGoodsInfo(basRepairGoods);
        if (i > 0) {
            return K.ok().data(basRepairGoods.getId());
        } else {
            return K.error();
        }
    }


    @ApiOperation(value = "删除维修物品相关表")
    @DeleteMapping("/delete/{id}")
//    @PreAuthorize("hasAuthority('basRepairGoods:delete')")
    public Object delete(@PathVariable("id") Integer id) {
        int i = basRepairGoodsService.deleteRepairGoodsInfo(id);
        if (i > 0) {
            return K.ok();
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据维修物品相关表名称分页获取维修物品相关表列表")
    @GetMapping("/list")
//    @PreAuthorize("hasAuthority('basRepairGoods:list')")
    public Object getList(BasRepairGoods basRepairGoods,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        IPage<BasRepairGoods> list = basRepairGoodsService.getRepairGoodsList(basRepairGoods, pageNum, pageSize);
        return K.ok().data(list);
    }

    @ApiOperation(value = "根据编号查询维修物品相关表信息")
    @GetMapping("/{id}")
//    @PreAuthorize("hasAuthority('basRepairGoods:get')")
    public Object getItem(@PathVariable("id") Integer id) {
        BasRepairGoods basRepairGoods = basRepairGoodsService.getById(id);
        return K.ok().data(basRepairGoods);
    }
}